package com.sxjh.aspect;


import com.sxjh.service.UserActionLogsService;
import com.sxjh.uitl.HttpContextUtils;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;


/**
 * 用户操作日志，切面处理类
 * 
 * @author lwj
 */
@Slf4j
@Aspect
@Component
public class UserLogAspect {


	@Resource
	private UserActionLogsService userActionLogsService;
	
	@Pointcut("@annotation(com.sxjh.annotation.UserLog)")
	public void logPointCut() { 
		
	}

	@Around("logPointCut()")
	public Object around(ProceedingJoinPoint point) throws Throwable {
		//执行方法
		Object result = point.proceed();
		//保存日志，不使用异步线程，因为HttpServletRequest值会有问题
		HttpServletRequest request = HttpContextUtils.getHttpServletRequest();
		try{
			userActionLogsService.saveLog(point, result, request);
		}catch (Exception ex){
			log.error("@@保存操作日志异常", ex);
		}
		return result;
	}


}
